package com.devilvan.betrice.util;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

/**
 * @author Evad.Wu
 * @Description 浏览器驱动 工具类
 * @date 2022-09-27
 */
public class ExploreDriverUtil {
    private static volatile ChromeDriver chromeDriver = null;

    /**
     * 构建单例ChromeDriver
     *
     * @return 单例chromeDriver
     */
    public static ChromeDriver getChromeDriver() {
        if (chromeDriver == null) {
            synchronized (ExploreDriverUtil.class) {
                if (chromeDriver == null) {
                    //配置本地的chromediver.exe谷歌的内核
                    System.setProperty("webdriver.chrome.driver", "D:\\搜狗高速下载\\chromedriver.exe");
                    //设置ChromeOptions打开方式，设置headless：不弹出浏览器
                    ChromeOptions options = new ChromeOptions();
                    options.addArguments("headless");
                    //设置好使用ChromeDriver使用
                    chromeDriver = new ChromeDriver(options);
                }
            }
        }
        return chromeDriver;
    }
}
